﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoodMan.Infrastructure.Entities.Repository;

namespace GoodMan.Infrastructure.Entities.Entity
{
    public class Policy : IAccessible<T_Policy, Policy>, ILogicEntity<T_Policy, Policy>
    {
        public int Id { get; set; }
        public int ProductId { get; set; }
        public string ProductName { get; set; }
        public decimal Price { get; set; }
        public int PolicyType { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime ExpireDate { get; set; }
        public bool IsActive { get; set; }
        public DateTime CreateDate { get; set; }
        public string Creator { get; set; }

        public int Integral { get; set; }

        protected override void Covariant(T_Policy model)
        {
            if (model != null)
            {
                this.CreateDate = model.CreateDate;
                this.Creator = model.Creator;
                this.ExpireDate = model.ExpireDate;
                this.Id = model.Id;
                this.IsActive = model.IsActive;
                this.PolicyType = model.PolicyType;
                this.Price = model.Price;
                this.ProductId = model.ProductId;
                this.ProductName = model.ProductName;
                this.StartDate = model.StartDate;
            }
        }

        protected override T_Policy Inverter(Policy model)
        {
            if (model != null)
            {
                return new T_Policy()
                {
                    CreateDate = model.CreateDate,
                    Creator = model.Creator,
                    ExpireDate = model.ExpireDate,
                    Id = model.Id,
                    IsActive = model.IsActive,
                    PolicyType = model.PolicyType,
                    Price = model.Price,
                    ProductId = model.ProductId,
                    ProductName = model.ProductName,
                    StartDate = model.StartDate
                };
            }
            return null;
        }

        public Policy Set(T_Policy dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
